package com.decent.web.system.dao.provider;

import cn.hutool.core.util.EnumUtil;
import com.decent.web.system.dto.SystemOrderDTO;

import java.util.Map;
import java.util.Objects;

/**
 * @author: decent Gjh
 * @date: 2022/11/02/9:42
 * @description:
 */
public class SystemOrderDaoProvider {

    /**
     * 条件查询的sql拼接
     * @param params dto
     * @return sql
     */
    public String list(Map<String, SystemOrderDTO> params) {
        SystemOrderDTO dto = params.get("order");
        StringBuilder sql = new StringBuilder(128);
        sql.append("select DISTINCT order_uuid,order_state,goods_name,good_id,brand_id,num,total_price,user_id,classify_id " +
                " from common_order " +
                " where user_id = #{order.userId} ");
        // 订单状态
        if (Objects.nonNull(dto.getOrderState())&&EnumUtil.isEnum(dto.getOrderState())) {
            sql.append(" and order_state = #{order.orderState} ");
        }
        sql.append(" order by create_datetime ");
        return sql.toString();
    }
}
